package com.intellagric.controller.module.trace_person;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.TracePersonType;
import com.intellagric.service.traceability.trace_person.PersonTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/6
 * @DESC： 人员类别信息管理
 */
@Controller
public class PersonTypeController {

    @Autowired
    private PersonTypeService personTypeService;

    /**
     * 添加人员类别信息
     * @Param personType
     * @return ResponseMessage
     */
    @RequestMapping("/person/type/add")
    @ResponseBody
    public ResponseMessage add(TracePersonType personType) {
        personType.setId(UUID.randomUUID().toString().replaceAll("-",""));
        personType.setCreateDate(new Date());
        personType.setUpdateDate(new Date());
        return personTypeService.addPersonType(personType);
    }


    /**
     * 删除人员类别信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/person/type/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return personTypeService.deletePersonType(id);
    }

    /**
     * 修改人员类别信息
     * @Param personType
     * @return ResponseMessage
     */
    @RequestMapping("/person/type/edit")
    @ResponseBody
    public ResponseMessage edit(TracePersonType personType) {
        personType.setUpdateDate(new Date());
        return personTypeService.editPersonType(personType);
    }

    /**
     * 查询人员类别信息
     * @return TracePersonType
     */
    @RequestMapping("/person/type/{id}")
    @ResponseBody
    public TracePersonType get(@PathVariable String id) {
        return personTypeService.getPersonTypeById(id);
    }


    /**
     * 查询所有人员类别树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/person/type/enterprise/tree")
    @ResponseBody
    public LayuiDataGridResult getTreeByCreateBy(String createBy) {
        return personTypeService.getPersonTypeTree(createBy);
    }



    /**
     * 查询所有人员类别树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/person/type/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return personTypeService.getPersonTypeTree();
    }

    /**
     * 查询所有人员类别树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/person/type/tree/select")
    @ResponseBody
    public List<TracePersonType> getTreeSelect() {
        return personTypeService.getPersonTypeTree().getData();
    }

    /**
     * 根据指定企业查询所有人员类别树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/person/type/tree/selectByCreateBy")
    @ResponseBody
    public List<TracePersonType> getTreeSelect(String createBy) {
        return personTypeService.getPersonTypeTree(createBy).getData();
    }
    /**
     * 查询所有人员类别信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/person/type/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return personTypeService.getPersonTypeList();
    }

}
